package com.kk.permission.progress;

import android.os.Handler;

import com.kk.permission.events.FinishEvent;
import com.kk.permission.utils.callershow.RxBus;

import java.util.List;
import java.util.Random;

public class ProgressUtil {
//    public static Spanned getProgressStateText(int i) {
//        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("修复中 <font color=\"");
//        stringBuilder.append(ResUtils.getColor(R.color.permission_progress_text_color));
//        stringBuilder.append("\">");
//        stringBuilder.append(i);
//        stringBuilder.append(Operation.MOD);
//        return Html.fromHtml(stringBuilder.toString());
//    }

    public static int getProgressStatePercent(List<ProgressState> list) {
        int i = 0;
        for (ProgressState progressState : list) {
            if (progressState.state == 1) {
                i++;
            }
        }
        if (i == list.size()) {
            return 100;
        }
        if (i == 0) {
            return 0;
        }
        return (100 / list.size()) * i;
    }

    public static void sendFinishEvent(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("sendFinishEvent>>>>");
        stringBuilder.append(str);
        RxBus.getIns().post(new FinishEvent(str));
    }

    public static void sendFinishEvent(final String str, int i) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("sendFinishEvent delay>>>>");
        stringBuilder.append(str);
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                RxBus.getIns().post(new FinishEvent(str));
            }
        });
//        UiThreadExecutor.execute(new Runnable() {
//            public void run() {
//                RxBus.getIns().post(new FinishEvent(str));
//            }
//        }, (long) i);
    }

    public static int generateRandomNum(int i, int i2) {
        return new Random().nextInt(i2) + i;
    }
}